/*
 * pso.h
 * Particle Swarm optimizer and related code.
 * Created on: 13 Feb, 2009
 */

#ifndef PSO_H_
#define PSO_H_

#include "utilities.h"
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;


// Definition of various Objectives
const int ECONOMIC_LOAD_DISPATCH = 1;
const int ENVIRONMENTAL_CONSTRAINT = 2;
const int VOLTAGE_PROFILE_IMPROVEMENT = 3;


// psoParameters will be a global variable which has the parameters used in PSO algorithm
// Declaration of @psoParameters struct
struct psoParameters{
  int particles;
  double inertiaWeight;
  double c1,c2;
  double alpha;
  static const int maxIterations = 500;
  static const int constIterations = 50;
  int objective;

  //Global PSO parameters that are to be set at the time of initialisation
  int dimensions;
  vector<double> gBestPosition;
  double gBestValue;

  //constructor
  psoParameters(int dim, int obj=1);
};

//Declaration of @Particle struct

struct Particle{
  int dimensions;
  vector<double> currentPosition, nextPosition;
  vector<double> particleVelocity;
  vector<double> pBest;
  double pBestvalue;
  int objective;


  Particle(vector<double> position, int obj);

  void updateParticle(struct psoParameters &global);
  double evaluateParticle();
  bool updateBest(struct psoParameters &global);
};


// An infinitely large number to aid during calculations
const double INF = double(1e10);

//Initial Global best evaluation function value. This is the value to be minimised
double evaluationFunction(vector<double> candidateVector);

#endif /* PSO_H_ */
